const mysql = require("mysql2");
const config = require("../config/index");

module.exports = () => {
  return async (ctx, next) => {
    const { host, user, password, database } = config.mysql;
    // create the connection
    const connection = mysql.createPool({
      host: host,
      user: user,
      password: password,
      database: database,
    }).promise();

    ctx.db = connection;
    // ctx.db = await connection.getConnection();

    await next();
  }
}
